#pragma once

#include "Misc/EngineEditorMacros.h"
#include "Object/Object.h"
#include "MaterialGraph/MaterialGraphValueType.h"
#include "Math/Math.h"
#include "MaterialGraphPinViewModel.m.h"

class RMaterialGraphPinModel;
class RMaterialGraphNodeViewModel;

RCLASS()
class RMaterialGraphPinViewModel : public RObject
{
    ROBJECT

public:
    virtual void BindModel(
        TSharedObjectPtr<RMaterialGraphPinModel> InModel
        ,TSharedObjectPtr<RMaterialGraphNodeViewModel> InNode
        ); 

    void SetLineIndex(int64_t InIndex);
    int64_t GetLineIndex() const;

    //get center X in node widget space
    float GetCenterXInNodeWidget();
    float GetCenterYInNodeWidget();

    float GetCenterXInGraphWidget();
    float GetCenterYInGraphWidget();

    void OnDragStarted();
    void OnDragEnded();

    float GetLineHeight() const;
    SColor GetPinColor() const;
    bool IsOutput() const;

    bool IsHidden() const;

    float GetDefaultX() const;
    void SetDefaultX(float InValue);

    float GetDefaultY() const;
    void SetDefaultY(float InValue);

    float GetDefaultZ() const;
    void SetDefaultZ(float InValue);

    SVec4 GetDefaultXYZW() const;

    TSharedObjectPtr<RMaterialGraphPinModel> GetModel() const;
    TSharedObjectPtr<RMaterialGraphNodeViewModel> 
        GetNodeViewModel();

    bool HasValidLink() const;

    //添加或移除了连接
    TDelegate<void> OnLinkChanged;
protected:

    TSharedObjectPtr<RMaterialGraphPinModel> BaseModel;

    TSharedObjectPtr<RMaterialGraphNodeViewModel> BaseNode;
    
    SColor PinColor;

    //line index in node,base 0
    int64_t LineIndex = 0;

    friend class RMaterialGraphViewModel;
};
